package com.xiguanlezz.cn.client.naming.remote.grpc;

import com.xiguanlezz.cn.api.remote.request.NotifySubscriberRequest;
import com.xiguanlezz.cn.api.remote.request.Request;
import com.xiguanlezz.cn.api.remote.response.NotifySubscriberResponse;
import com.xiguanlezz.cn.api.remote.response.Response;
import com.xiguanlezz.cn.client.naming.cache.ServiceInfoHolder;
import com.xiguanlezz.cn.common.remote.client.Connection;
import com.xiguanlezz.cn.common.remote.client.ServerRequestHandler;
import lombok.AllArgsConstructor;

/**
 * @Author：习惯了种种
 * @CreateDate：2024/11/28 11:22
 * @Description：服务端主动推送服务实例信息的客户端处理器
 */
@AllArgsConstructor
public class NamingPushRequestHandler implements ServerRequestHandler {
    private ServiceInfoHolder serviceInfoHolder;


    @Override
    public Response requestReply(Request request, Connection connection) {
        if (request instanceof NotifySubscriberRequest) {
            NotifySubscriberRequest notifyRequest = (NotifySubscriberRequest) request;
            serviceInfoHolder.processServiceInfo(notifyRequest.getServiceInfo());
            return new NotifySubscriberResponse();
        }
        return null;
    }
}
